package com.zhuoshi.utils;

import java.text.SimpleDateFormat;

public class DateHelper {
	/** 
     * @param 返回java.sql.Date格式的 
     * 
     * */  
	public static java.sql.Date strToDate(String strDate) {  
        String str = strDate;  
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");  
        java.util.Date d = null;  
        try {  
            d = format.parse(str);  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
        java.sql.Date date = new java.sql.Date(d.getTime());  
        return date;  
    }  
	
	/** 
	  * @param 返回java.sql.Time格式的 
	  * 
	  * */  
	 @SuppressWarnings("static-access")
	public static java.sql.Time strToTime(String strDate) {  
	     String str = strDate;  
	     SimpleDateFormat format = new SimpleDateFormat("hh:mm:ss");  
	     java.util.Date d = null;  
	     try {  
	         d = format.parse(str);  
	     } catch (Exception e) {  
	         e.printStackTrace();  
	     }  
	     java.sql.Time time = new java.sql.Time(d.getTime());  
	     return time.valueOf(str);  
	 } 
	 
	 @SuppressWarnings("static-access")
	public static java.sql.Date strToDateTime(String strDate){
		 String str = strDate;
		 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		 java.util.Date d = null;
		 try {
			d = format.parse(str);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		java.sql.Date dateTime = new java.sql.Date(d.getTime());
		return dateTime.valueOf(str);
	 }
}
